package de.justphil.tcg.tcgserver.commons.domain;


import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import de.justphil.tcg.tcgserver.commons.util.DateTimeUtil;

@Entity
@Table(name = "properties", schema = "tcg")
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class Property implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2007326512710427135L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "property_id")
	@XmlElement
	private long id;
	
	@Column(name = "name")
	private String name;
	
	@Column(name = "created")
	@Temporal(TemporalType.TIMESTAMP)
	private Date created;
	
	@Column(name = "modified")
	@Temporal(TemporalType.TIMESTAMP)
	private Date modified;
	
	
	

	public Property() {
		// JPA requires a default constructor without parameters
	}
	
	public Property(String name) {
		this.name = name;
		
		long nowUTC = DateTimeUtil.getUTCTimeInMillis();
		this.created = new Date(nowUTC);
		this.modified = new Date(nowUTC);
	}

	/* ############################################################################################ */
	/* ############################################################################################ */
	/* ############################################################################################ */
	
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getCreated() {
		return created;
	}

	public Date getModified() {
		return modified;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public void setModified(Date modified) {
		this.modified = modified;
	}

	
	/* ############################################################################################ */
	/* ############################################################################################ */
	/* ############################################################################################ */

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (id ^ (id >>> 32));
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Property other = (Property) obj;
		if (id != other.id)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	
	/* ############################################################################################ */
	/* ############################################################################################ */
	/* ############################################################################################ */

	/*
	@Override
	public void readData(DataInput in) throws IOException {
		id = in.readLong();
		name = in.readUTF();
		created = new Date(in.readLong());
		modified = new Date(in.readLong());
	}

	@Override
	public void writeData(DataOutput out) throws IOException {
		out.writeLong(id);
		out.writeUTF(name);
		out.writeLong(created.getTime());
		out.writeLong(modified.getTime());
	}
	*/
	
}
